package com.zfzs.post.controller;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.exception.BadRequestException;
import com.zfzs.post.kuaidi.KuaiDiUtils;
import com.zfzs.post.model.vo.GoodsListVO;
import com.zfzs.post.model.vo.GoodsVO;
import com.zfzs.post.service.GoodsAboutService;
import com.zfzs.post.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.prefs.BackingStoreException;

/**
 * @author wq
 * @date 2019/10/8 17:43
 * @description 物料商城控制器
 */
@Slf4j
@RestController
@RequestMapping("goods/")
public class GoodsController {

    @Autowired
    private GoodsAboutService goodsAboutService;

    /**
     * 获取商品列表
     */
    @Log("获取商品列表")
    @PostMapping(value = "get_goods_list")
    public ResponseResult getGoodsList(@RequestBody Map<String, Object> params) {
        Integer goodsType = Integer.valueOf(params.get("goodsType").toString());
        List<GoodsListVO> list = goodsAboutService.getGoodsList(goodsType);
        return ResponseResult.ok(new HashMap<String, Object>(1) {{
            put("list", list);
        }});
    }


    /**
     * 根据id获取商品
     */
    @Log("根据id获取商品")
    @PostMapping(value = "get_goods_byId")
    public ResponseResult getGoodsById(@RequestBody Map<String, String> params) {
        String id = params.get("goodsId");
        GoodsVO v = goodsAboutService.getGoodsById(id);
        return ResponseResult.ok(v);
    }

    /**
     * 获取商品类别列表
     */
    @Log("获取商品类别列表")
    @PostMapping(value = "get_goods_type")
    public ResponseResult getGoodsType() {
        List<Map<String, String>> list = goodsAboutService.getGoodsType();
        return ResponseResult.ok(new HashMap<String, List>(1) {{
            put("list", list);
        }});
    }

    /**
     * 获取快递信息
     */

    @Log("获取快递信息")
    @PostMapping(value = "get_kuaidi_info")
    public ResponseResult getKuaiDiInfo(@RequestBody Map<String, String> params) {
        return ResponseResult.ok("查询成功", goodsAboutService.getKuaiDiInfo(params));
    }
}
